From 5c966f1b59beaf250d84173307e82293d62ab4c7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 8 Dec 2014 20:24:27 -0800 Subject: [PATCH] Migrate to std::sync::TaskPool No need to have our own bundled implementation when the standard library suffices! --- src/cargo/ops/cargo_rustc/job_queue.rs | 3 +- src/cargo/util/mod.rs | 2 -- src/cargo/util/pool.rs | 42 -------------------------- 3 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 src/cargo/util/pool.rs diff --git a/src/cargo/ops/cargo_rustc/job_queue.rs b/src/cargo/ops/cargo_rustc/job_queue.rs index 735fd165e..256ee73cd 100644 --- a/src/cargo/ops/cargo_rustc/job_queue.rs +++ b/src/cargo/ops/cargo_rustc/job_queue.rs @@ -1,9 +1,10 @@ use std::collections::HashSet; use std::collections::hash_map::{HashMap, Occupied, Vacant}; +use std::sync::TaskPool; use term::color::YELLOW; use core::{Package, PackageId, Resolve, PackageSet}; -use util::{Config, TaskPool, DependencyQueue, Fresh, Dirty, Freshness}; +use util::{Config, DependencyQueue, Fresh, Dirty, Freshness}; use util::{CargoResult, Dependency, profile}; use super::job::Job; diff --git a/src/cargo/util/mod.rs b/src/cargo/util/mod.rs index e23ab7dc0..18daf6d97 100644 --- a/src/cargo/util/mod.rs +++ b/src/cargo/util/mod.rs @@ -6,7 +6,6 @@ pub use self::errors::{CliError, FromError, ProcessError}; pub use self::errors::{process_error, internal_error, internal, human, caused_human}; pub use self::paths::{realpath, join_paths}; pub use self::hex::{to_hex, short_hash}; -pub use self::pool::TaskPool; pub use self::dependency_queue::{DependencyQueue, Fresh, Dirty, Freshness}; pub use self::dependency_queue::Dependency; pub use self::graph::Graph; @@ -28,6 +27,5 @@ pub mod to_semver; pub mod to_url; pub mod toml; mod dependency_queue; -mod pool; mod sha256; mod vcs; diff --git a/src/cargo/util/pool.rs b/src/cargo/util/pool.rs deleted file mode 100644 index 1dc2d7345..000000000 --- a/src/cargo/util/pool.rs +++ /dev/null @@ -1,42 +0,0 @@ -//! A load-balancing task pool. -//! -//! This differs in implementation from std::sync::TaskPool in that each job is -//! up for grabs by any of the child tasks in the pool. -//! -//! This should be upstreamed at some point. - -use std::sync::{Arc, Mutex}; - -pub struct TaskPool { - tx: SyncSender, -} - -impl TaskPool { - pub fn new(tasks: uint) -> TaskPool { - assert!(tasks > 0); - let (tx, rx) = sync_channel(tasks); - - let state = Arc::new(Mutex::new(rx)); - - for _ in range(0, tasks) { - let state = state.clone(); - spawn(proc() worker(&*state)); - } - - return TaskPool { tx: tx }; - - fn worker(rx: &Mutex>) { - loop { - let job = rx.lock().recv_opt(); - match job { - Ok(job) => job(), - Err(..) => break, - } - } - } - } - - pub fn execute(&self, job: proc():Send) { - self.tx.send(job); - } -} -- 2.30.2